package com.dingding.queue.queue.producer;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.SendResult;
import com.dingding.common.core.config.MessageQueueConfig;
import com.dingding.common.core.config.SystemConfig.TagsEnum;
import com.dingding.common.core.util.ToolUtil;

/**
 * 
 * @ClassName: BusinessProducer
 * @Description: 业务执行生产者
 * @author yuHaiQing
 * @date 2016年8月11日 上午11:46:34
 * @since V2.4.0
 * 
 */
@Component("businessProducer")
public class BusinessProducer implements IBusinessProducer {

	private static final Logger log = Logger.getLogger(BusinessProducer.class);

	@Resource(name = "producerFactory")
	private ProducerFactory producerFactory;
	/**
	 * 
	 * @Title: executeBusiness
	 * @Description: 执行业务操作
	 * @param content 参数
	 * @author yuHaiQing
	 * @since V2.4.0
	 * @return boolean    返回类型
	 * 
	 */
	@Override
	public boolean executeBusiness(String content) {

		
		
		Message msg = new Message(MessageQueueConfig.getMESSAGE_QUEUE_TOPIC(), TagsEnum.BUSINESS.toString(),
				content.getBytes());
		try {
			SendResult sendResult = producerFactory.producer.send(msg);
			if (sendResult != null && ToolUtil.isNotBlank(sendResult.getMessageId())) { // 发送成功
				return true;
			}
		} catch (Exception e) {
			log.error("发送消息到队列中出现异常！BusinessProducer：executeBusiness", e);
		}

		return false;

	}

}
